package com.yaosheng.thread.interview;

import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.TransferQueue;

/**
 * Created by yaosheng on 2021/7/6.
 */
public class TransferQueueView {

    public static void main(String[] args) {

        char[] aI = "1234567".toCharArray ();
        char[] aC = "ABCDEFG".toCharArray ();

        TransferQueue<Character> queue = new LinkedTransferQueue<> ();

        new Thread ( () -> {
            try{
                for(char c : aI){
                    System.out.println (queue.take ());
                    queue.transfer (c);
                }
            } catch (InterruptedException e) {
                e.printStackTrace ();
            }
        },"t1").start ();

        new Thread ( () -> {
            try{
                for(char c : aC){
                    System.out.println (queue.take ());
                    queue.transfer (c);
                }
            } catch (InterruptedException e) {
                e.printStackTrace ();
            }
        },"t2").start ();
    }
}
